package com.peng.controller;

import com.peng.mapper.DeptMapper;
import com.peng.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptMapper mapper;

    @Autowired
    private DiscoveryClient client;

    @PostMapping("/dept/add")
    public boolean add(@RequestBody Dept dept){
        return mapper.addDept(dept);
    }
    @GetMapping("/dept/id/{id}")
    public Dept queryId(@PathVariable("id") long id){
        return mapper.queryId(id);
    }
    @GetMapping("/dept/all")
    public List<Dept> queryAll(){
        return mapper.queryList();
    }

    @RequestMapping("/dept/dis")
    public Object discovery(){
        List<String> services = client.getServices();
        System.out.println(services);
        List<ServiceInstance> instances = client.getInstances("springcloud-provider-dept");
        for (ServiceInstance instance : instances) {
            System.out.println(instance.getUri());
        }
        return this.client;
    }
}
